package com.tansun.easycare.rule.common.model;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import com.tansun.easycare.rule.table.entity.RuleDecisiontableDetail;

/**
 * 规则基础信息
 *
 * @author Lph
 */
public class BaseItem implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = 709024010556887943L;
    /**
     * 参数类名
     */
    private String className;
    /**
     * 英文参数名
     */
    private String nameEN;
    /**
     * 中文参数名
     */
    private String nameCN;
    /**
     * 参数域
     */
    private String domain;
    /**
     * 参数数据类型
     */
    private String dataType;
    /**
     * 是否集合
     */
    private String collection;
    /**
     * 集合类型下标
     */
    private String position;

    private String pattern;
    /**
     * 缺省值
     */
    private String defaultValue;
    /**
     * 是否衍生变量
     */
    private String isDerives;
    /**
     * 公式明文
     */
    private String formulaLabel;
    /**
     * 公式暗文
     */
    private String formula;
    /**
     * 是否函数变量
     */
    private String isfuncparam;
    
    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getNameEN() {
        return nameEN;
    }

    public void setNameEN(String nameEN) {
        this.nameEN = nameEN;
    }

    public String getNameCN() {
        return nameCN;
    }

    public void setNameCN(String nameCN) {
        this.nameCN = nameCN;
    }

    public String getDataType() {
        return dataType;
    }

    public void setDataType(String dataType) {
        this.dataType = dataType;
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    public String getPosition() {
        return position;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public String getDefaultValue() {
        return defaultValue;
    }

    public void setDefaultValue(String defaultValue) {
        this.defaultValue = defaultValue;
    }

    public String getIsDerives() {
        return isDerives;
    }

    public void setIsDerives(String isDerives) {
        this.isDerives = isDerives;
    }

    public String getCollection() {
        return collection;
    }

    public void setCollection(String collection) {
        this.collection = collection;
    }

    public String getFormulaLabel() {
		return formulaLabel;
	}

	public void setFormulaLabel(String formulaLabel) {
		this.formulaLabel = formulaLabel;
	}

	public String getFormula() {
		return formula;
	}

	public void setFormula(String formula) {
		this.formula = formula;
	}
	public String getIsfuncparam() {
		return isfuncparam;
	}

	public void setIsfuncparam(String isfuncparam) {
		this.isfuncparam = isfuncparam;
	}

	public Object deepCopy() throws Exception {
        // 将该对象序列化成流,因为写在流里的是对象的一个拷贝，而原对象仍然存在于JVM里面。所以利用这个特性可以实现对象的深拷贝  
        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        ObjectOutputStream oos = new ObjectOutputStream(bos);

        oos.writeObject(this);

        // 将流序列化成对象  
        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());

        ObjectInputStream ois = new ObjectInputStream(bis);

        return ois.readObject();
    }

    public void initModel(BomField param) {
        this.setClassName(param.getClassName());
        this.setNameCN(param.getLabel());
        this.setNameEN(param.getName());
        this.setDomain(param.getDomain());
        this.setDataType(param.getDataType());
        this.setCollection(param.getCollection());
    }

    public String getPattern() {
        return pattern;
    }

    public void setPattern(String pattern) {
        this.pattern = pattern;
    }

    public BaseItem() {
    }

    public BaseItem(RuleDecisiontableDetail tdDetail) {
        this.setClassName(tdDetail.getClassName());
        this.setNameCN(tdDetail.getNamecn());
        this.setNameEN(tdDetail.getNameen());
        this.setDomain(tdDetail.getDomain());
        this.setDataType(tdDetail.getDataType());
    }
}
